package com.powernode.interceptor;

import com.powernode.commons.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //如果session里面有user对象，就证明已经登录，放行
        Object user = request.getSession().getAttribute(Constants.SESSION_USER_KEY);
        if(null!=user){
            return true;
        }
        //跳转到登录界面
        response.sendRedirect("/index.html");
        return false;
    }
}
